//
//  TransferShopHeaderCell.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/8/31.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
protocol TransferShopHeaderCellDelegate {
    func callAction()
    func reportAction()
    func ivSelected()
}
class TransferShopHeaderCell: UITableViewCell {
    var model: TransferDetailModel? {
        didSet {
            self.setCellContentWithCellInfo((self.model?.body)!)
            self.setupView()
        }
    }
    var delegate: TransferShopHeaderCellDelegate?
    @IBOutlet weak var titel: UILabel!
    @IBOutlet weak var time: UILabel!
    @IBOutlet weak var redTitle: UILabel!
    @IBOutlet weak var browNum: UILabel!
    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var shopSize: UILabel!
    @IBOutlet weak var treasureType: UILabel!
    @IBOutlet weak var rent: UILabel!
    @IBOutlet weak var area: UILabel!
    @IBOutlet weak var address: UILabel!
    @IBOutlet weak var name: UILabel!
    @IBOutlet weak var tel: UILabel!
    @IBOutlet weak var body: UILabel!
    @IBOutlet weak var cyclePicture: CyclePictureView!
    @IBOutlet weak var boayView: UIView!
    @IBOutlet weak var advertisersIv: UIImageView!
    @IBOutlet weak var advertisersName: UILabel!
    @IBOutlet weak var bodyConst: NSLayoutConstraint!
    override func awakeFromNib() {
        super.awakeFromNib()
        self.advertisersIv.layer.cornerRadius = 16.5
        self.advertisersIv.layer.masksToBounds = true
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func setCellContentWithCellInfo(text: String) -> Void {
        let font = UIFont(name: "Helvetica", size: 16)
        let height = publicMethod.getLabHeigh(text, font: font!, width: SCREEN_WIDTH - 16) + 29 + 15
        
        self.bodyConst.constant = height
        self.boayView.layoutIfNeeded()
        
    }
    func setupView() -> Void {

        time.text = publicMethod.computationTimeDifference((model?.ptime)!)
        browNum.text = String(format: "已有%@人浏览",(model!.browerNum))
        redTitle.text = model?.price
        name.text = model?.contacts
        titel.text = model?.name
        price.text = model?.price
        shopSize.text = model?.size
        treasureType.text = model?.treasureType
        rent.text = model?.rent
        area.text = model?.area
        address.text = model?.address
        tel.text = model?.tel
        body.text = model?.body
        advertisersIv.sd_setImageWithURL(NSURL(string: model!.usertimg), placeholderImage: UIImage(named: "placeholder"))
        advertisersName.text = model?.username
        
        var images: [String] = []
        for item in model!.transferPics {
            images.append(item.imgurl)
        }
        
        cyclePicture.imageURLArray = images
    }
    @IBAction func callBtnClicked(sender: UIButton){
        delegate?.callAction()
    }
    @IBAction func reportAction(sender: UIButton){
        delegate?.reportAction()
    }
    @IBAction func ivTap(sender: UIButton) {
        delegate?.ivSelected()
    }

    
}
